<?php
use NoahBuscher\Macaw\Macaw;
Macaw::get('(:all)', function($url){	
	$url=explode("/",$url);
	$count=count($url);	

	$module=($count<1 || $url[0]=="")?'Index':ucfirst(strtolower($url[0]));
	$controller=($count<2 || $url[1]=="")?'Index':ucfirst(strtolower($url[1]));
	$action=($count<3 || $url[2]=="")?'index':strtolower($url[2]);
	   define('MODULE_NAME',$module);
	   define('CONTROLLER_NAME',$controller);
	   define('ACTION_NAME',$action);
	
	$obj='Controllers\\'.$module.'\\'.$controller;
	$last=end($url);
	if(!strpos($last,'.')){
		if(class_exists($obj)){		
			$run=new $obj();			
		}else{
			controller::error("对象".$obj."不存在");
		}
		if(method_exists($run,$action)){	
					
			$run->{$action}();
		}else{
			controller::error("对象".$obj.",方法".$action."不存在");
		}
	}
	
	
	
});
Macaw::$error_callback = function() {

	throw new Exception("路由无匹配项 404 Not Found");

};
Macaw::dispatch();